
var SUBMIT_TYPE = 1;//提交
var REVIEW_TYPE = 2;//审核
var UNREVIE_TYPE = 3;//反审核
var ENABLED_TYPE = 1;//启用
var DISABLED_TYPE = 1;//禁用

/**
 * @description 批量处理提交.<br>
 * @param gridId 列表的gridId.<br>
 * @param url 访问地址.<br>
 * @param otherParams 其他参数.<br>
 * @param callBack 回调函数.<br>
 */
function submit(title,url,gridId,width,height,callBack,otherParams){
	operate(SUBMIT_TYPE,gridId,url,otherParams,callBack);
}

/**
 * @description 批量审核.<br>
 * @param gridId 列表的gridId.<br>
 * @param url 访问地址.<br>
 * @param otherParams 其他参数.<br>
 * @param callBack 回调函数.<br>
 */
function review(title,url,gridId,width,height,callBack,otherParams){
	operate(REVIEW_TYPE,gridId,url,otherParams,callBack);
}

/**
 * @description 批量反审核.<br>
 * @param gridId 列表的gridId.<br>
 * @param url 访问地址.<br>
 * @param otherParams 其他参数.<br>
 * @param callBack 回调函数.<br>
 */
function unreview(title,url,gridId,width,height,callBack,otherParams){
	operate(UNREVIE_TYPE,gridId,url,otherParams,callBack);
}

/**
 * @description 导入excel.<br>
 * @param title 弹出框名称.<br>
 * @param url 公共打开Excel上传界面的url.<br>
 * @param gridId grid的Id.<br>
 * @param width 弹出框宽度.<br>
 * @param height 弹出框高度.<br> 
 * @param controllerUrl 上传excel的地址.<br>
 * @param otherParams 其他参数.<br>
 * @param callBack 回调函数.<br>
 */
function impexcel(title,url,gridId,width,height,callBack,otherParams,controllerUrl){
	if(url.indexOf('?')!=-1){
		 url = url + '&controllerName='+controllerUrl;
	}else{
		 url = url + '?controllerName='+controllerUrl;
	}
	if(typeof (otherParams) == "object" 
		&& Object.prototype.toString.call(otherParams).toLowerCase() == "[object object]" 
			&& !otherParams.length){
		//用javascript的for/in循环遍历对象的属性 
		for(var i in otherParams){
			url = url +'&'+i+'='+otherParams[i];
		} 
	}
	uploadExcel(title,url,gridId,width,height,callBack);
}

/**
 * @description 导出excel模板.<br>
 * @param url 访问地址.<br>
 * @param gridId grid的Id.<br>
 * @param otherParams 其他参数.<br>
 */
function expexcelmodel(title,url,gridId,width,height,callBack,otherParams){
	if(url.indexOf('?')!=-1){
		 url = url + '&gridId='+gridId;
	}else{
		 url = url + '?gridId='+gridId;
	}
	if(typeof (otherParams) == "object" 
		&& Object.prototype.toString.call(otherParams).toLowerCase() == "[object object]" 
			&& !otherParams.length){
		//用javascript的for/in循环遍历对象的属性 
		for(var i in otherParams){
			url = url +'&'+i+'='+otherParams[i];
		} 
	}
	window.open(url);
}

/**
 * @description 导出excel.<br>
 * @param url 访问地址.<br>
 * @param gridId grid的Id.<br>
 * @param otherParams 其他参数.<br>
 */
function expexcel(title,url,gridId,width,height,callBack,otherParams){
	if(url.indexOf('?')!=-1){
		 url = url + '&gridId='+gridId;
	}else{
		 url = url + '?gridId='+gridId;
	}
	if(typeof (otherParams) == "object" 
		&& Object.prototype.toString.call(otherParams).toLowerCase() == "[object object]" 
			&& !otherParams.length){
		//用javascript的for/in循环遍历对象的属性 
		for(var i in otherParams){
			url = url +'&'+i+'='+otherParams[i];
		} 
	}
	window.open(url);
}


/**
 * @description 启用 .<br>
 * @param gridIdgrid的Id .<br>
 * @param url url访问地址.<br>
 * @param otherParams 其他参数.<br>
 * @param callBack 回调函数.<br>
 */
function enabled(title,url,gridId,width,height,callBack,otherParams){
	operate(ENABLED_TYPE,gridId,url,otherParams,callBack);
}

/**
 * @description 禁用 .<br>
 * @param gridIdgrid的Id .<br>
 * @param url url访问地址.<br>
 * @param otherParams 其他参数.<br>
 * @param callBack 回调函数.<br>
 */
function unabled(title,url,gridId,width,height,callBack,otherParams){
	operate(DISABLED_TYPE,gridId,url,otherParams,callBack);
}

/**
 * @description 批量处理.<br>
 * @param optType 操作类型（-1:删除;1：提交,2：审核,3：反审核,5：打回）.<br>
 * @param gridId 列表的gridId.<br>
 * @param url 访问地址.<br>
 * @param otherParams 其他参数.<br>
 * @param callBack 回调函数.<br>
 */
function operate(optType,gridId,url,otherParams,callBack){
	 var params = {};
	 var menuId = window.localStorage? localStorage.getItem("nid"): Cookie.read("nid");
	 var rows = $("#"+gridId).jqGrid('getGridParam','selarrrow');
	 if(rows.length==0){
		 layer.msg('请至少选择一条数据', {icon: 2, time: 1000});
		 return;
	 }
	 if(url.indexOf('?')!=-1){
		 url = url + '&optType='+optType;
	 }else{
		 url = url + '?optType='+optType;
	 }
	 if(typeof (otherParams) == "object" && Object.prototype.toString.call(otherParams).toLowerCase() == "[object object]" && !otherParams.length){	 
		 params = otherParams;
	 }
	 params.menuId = menuId;
	 params.ids = rows.join(',');
	 var index = openLoad();
	 $.ajax({
		  type: 'POST',
		  url: url,
		  data: params,
		  dataType: 'json',
		  success: function(data){
			  closeLoad(index);
			  if(callBack){
				  callBack(data);
			  }else{
				  layer.msg(data.msg, {icon: 1, time: 1000});
				  delete params.ids;
				  search(gridId,params);
			  }
		  }
	});	
}

/**
 * @description 打开layer的加载层.<br>
 * @returns 返回打开的阴影层的下标.<br>
 * @author zcg.<br>
 */
function openLoad(){
	return top.layer.load(0, {
		content: '<span style="color: red;">处理中...</span>',
		shade: [0.3,'#fff'],
		shadeClose : false
	});
}

/**
 * @description 关闭layer的加载层.<br>
 * @returns 返回打开的阴影层的下标.<br>
 * @author zcg.<br>
 */
function closeLoad(index){
	top.layer.close(index);
}

/**
 * @description 查看附件.<br>
 * @param title:标题,url：地址,gridId：列表Id,id:id,width:宽度,height：高度
 * 
 */
function rowShowFile(title,url,gridId,id,value,width,height){
	 width = width?width:'60%';
	 height = height?height:'60%';
	 if(!value){
		 return '';
	 }
	 var href = '';
	 //href +="<a href=\"#\" class=\"btn btn-success btn-clip\" class=\"btn btn-success btn-clip \"";
	 href +="<a href=\"#\" class=\" btn-clip\" style=\"background-color:transparent!important\"";
	 href +="onclick=\"rowDialogDetailRefresh('"+title+"','"+url+"','"+gridId+"','"+id+"','"+width+"','"+height+"')\"";
	 href +="><i class=\"fa fa-paperclip\"></i></a>";
	 return href;
}
